package com.boc_eu.adoweb.adows.adoscript;

import java.rmi.RemoteException;

import javax.xml.rpc.holders.IntHolder;
import javax.xml.rpc.holders.StringHolder;

import org.adoxx.adows.client.ADOxxWebService;

/**
 * @author wutz
 *
 *         Abstract class to handle all AdoScript-based implementations of
 *         service calls. The execute methods is called by all implementations
 *         and performs the call of the service as well as logging
 *
 */
public abstract class AdoScript {
    protected IntHolder errorCode = new IntHolder();
    protected StringHolder result = new StringHolder();

    void execute(ADOxxWebService service, String script, String resultVariable) {
	try {
	    System.out.println("DEBUG: " + script);
	    service.getBinding().execute(script, resultVariable, errorCode, result);
	} catch (RemoteException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
    }

    /**
     * Access to the AdoScript errorcode
     * 
     * @return errorCode as an int
     */
    public int getErrorCode() {
	return errorCode.value;
    }

    /**
     * Access to the result of the AdoScript
     * 
     * @return String representation of result
     */
    public String getResult() {
	return result.value;
    }

}